package com.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author: may
 * @date: 2021年04月08日 20:31
 */
public class TestCyclicBarrier {

    public static void main(String[] args) {
        CyclicBarrier cb = new CyclicBarrier(20, () -> System.out.println("人满，发车！！！"));
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                try {
                    cb.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
